package com.ellecity06.cwhiskymall.view.dialog

import android.view.LayoutInflater
import android.view.View
import androidx.fragment.app.FragmentActivity
import com.ellecity06.common.base.BaseDialog
import com.ellecity06.cwhiskymall.databinding.DialogReceiveBinding

/**
 * @author ellecity06
 * @time 2024/11/6 16:16
 * @des
 */
class ReceiveDialog(activity: FragmentActivity, private val block: () -> Unit) :
    BaseDialog<DialogReceiveBinding>(activity),
    View.OnClickListener {
    override val dimAmount: Float
        get() = 0.8F

    override fun inflaterViewBinding(): DialogReceiveBinding {
        return DialogReceiveBinding.inflate(LayoutInflater.from(context))
    }

    override fun initialize() {
        binding.tvReceive.setOnClickListener(this)
        binding.ivClose.setOnClickListener(this)

    }

    fun show(receive: Boolean) {
        binding.tvReceive.isEnabled = receive
        binding.tvReceive.text = if (receive) "立即领取" else "已领取"
        super.show()
    }

    override fun onClick(view: View?) {
        when (view?.id) {
            binding.tvReceive.id -> {
                block.invoke()
            }
            binding.ivClose.id -> {
                dismiss()
            }
        }
    }
}